home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / util / geticonset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-29  |  3.6 KB  |  150 lines

  1. /* geticonset.c - outputs icon configuration from WindowMaker to stdout
  2.  *
  3.  *  Window Maker window manager
  4.  * 
  5.  *  Copyright (c) 1997, 1998, 1999 Alfredo K. Kojima
  6.  * 
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
  20.  *  USA.
  21.  */
  22.  
  23. #define PROG_VERSION "geticonset (Window Maker) 0.1"
  24.  
  25.  
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <proplist.h>
  29. #include <string.h>
  30.  
  31. #include "../src/wconfig.h"
  32.  
  33.  
  34.  
  35. char *ProgName;
  36.  
  37.  
  38. char*
  39. defaultsPathForDomain(char *domain)
  40. {
  41.     char path[1024];
  42.     char *gspath, *tmp;
  43.  
  44.     gspath = getenv("GNUSTEP_USER_ROOT");
  45.     if (gspath) {
  46.     strcpy(path, gspath);
  47.     strcat(path, "/");
  48.     } else {
  49.     char *home;
  50.     
  51.     home = getenv("HOME");
  52.     if (!home) {
  53.         printf("%s:could not get HOME environment variable!\n", ProgName);
  54.         exit(0);
  55.     }
  56.     strcpy(path, home);
  57.     strcat(path, "/GNUstep/");
  58.     }
  59.     strcat(path, DEFAULTS_DIR);
  60.     strcat(path, "/");
  61.     strcat(path, domain);
  62.  
  63.     tmp = malloc(strlen(path)+2);
  64.     strcpy(tmp, path);
  65.     
  66.     return tmp;
  67. }
  68.  
  69. void
  70. print_help()
  71. {
  72.     printf("Usage: %s [OPTIONS] [FILE]\n", ProgName);
  73.     puts("Retrieves program icon configuration and output to FILE or to stdout");
  74.     puts("");
  75.     puts("  --help    display this help and exit");
  76.     puts("  --version    output version information and exit");
  77. }
  78.  
  79.  
  80. int 
  81. main(int argc, char **argv)
  82. {
  83.     proplist_t window_name, icon_key, window_attrs, icon_value;
  84.     proplist_t all_windows, iconset;
  85.     proplist_t keylist;
  86.     char *path;
  87.     int i;
  88.  
  89.  
  90.     ProgName = argv[0];
  91.  
  92.     for (i = 1; i < argc; i++) {
  93.     if (strcmp(argv[i], "-h")==0
  94.         || strcmp(argv[i], "--help")==0) {
  95.         print_help();
  96.         exit(0);
  97.     } else if (strcmp(argv[i], "--version")==0) {
  98.         puts(PROG_VERSION);
  99.         exit(0);
  100.     }
  101.     }
  102.     
  103.     path = defaultsPathForDomain("WMWindowAttributes");
  104.     
  105.     all_windows = PLGetProplistWithPath(path);
  106.     if (!all_windows) {
  107.     printf("%s:could not load WindowMaker configuration file \"%s\".\n", 
  108.            ProgName, path);
  109.     exit(1);
  110.     }
  111.  
  112.     iconset = PLMakeDictionaryFromEntries(NULL, NULL, NULL);
  113.  
  114.     keylist = PLGetAllDictionaryKeys(all_windows);
  115.     icon_key = PLMakeString("Icon");
  116.     
  117.     for (i=0; i<PLGetNumberOfElements(keylist); i++) {
  118.     proplist_t icondic;
  119.     
  120.     window_name = PLGetArrayElement(keylist, i);
  121.     if (!PLIsString(window_name))
  122.         continue;
  123.         
  124.     window_attrs = PLGetDictionaryEntry(all_windows, window_name);
  125.     if (window_attrs && PLIsDictionary(window_attrs)) {
  126.         icon_value = PLGetDictionaryEntry(window_attrs, icon_key);
  127.         if (icon_value) {
  128.         
  129.         icondic = PLMakeDictionaryFromEntries(icon_key, icon_value, 
  130.                               NULL);
  131.  
  132.         PLInsertDictionaryEntry(iconset, window_name, icondic);
  133.         }
  134.     }
  135.     }
  136.     
  137.  
  138.     if (argc==2) {
  139.     proplist_t val;
  140.     val = PLMakeString(argv[1]);
  141.     PLSetFilename(iconset, val);
  142.     PLSave(iconset, NO);
  143.     } else {
  144.     puts(PLGetDescriptionIndent(iconset, 0));
  145.     }
  146.     exit(0);
  147. }
  148.  
  149.  
  150.